/*
*  general.c - utility functions
*  Copyright (c) 2008 Derek Ingrouville (dergro@users.sourceforge.net)
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU Library General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <glib.h>

#ifdef _W32_
#include <windows.h>    /* Sleep() */
#else
#include <unistd.h>     /* usleep() */
#endif /* _W32_ */

#include "utility.h"

char *url_decode (const char *enc)
{
	return g_uri_unescape_string (enc, NULL);
}

char *url_encode (const char *dec)
{
	/* Change the last parameter (0) to allow UTF-8 */
	return g_uri_escape_string (dec, NULL, 0);
}

char *get_cache_dir (void)
{
	char *dir = g_strconcat (g_get_home_dir (), DELIM, PROG_DIR, NULL);
	return dir;
}

void vobri_sleep (unsigned int microseconds)
{
	int secs = 0;

#ifndef _W32_
	usleep (microseconds);
#else
	secs = microseconds / 1000;
	Sleep (secs);
#endif /* _W32_ */
}
